﻿@model UniversityPortal.Models.RegisterModel
@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<h2>Create User</h2>

@using (Html.BeginForm("CreateAdmin", "User"))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <div class="editor-label">
            @Html.LabelFor(model => model.FirstName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FamilyName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FamilyName)
            @Html.ValidationMessageFor(model => model.FamilyName)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Email)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)
        </div>

        <div class="editor-label">
            UserType
        </div>
        <select id="UserType">
            <option value="1">Admin</option>
            <option value="2">Student</option>
            <option value="3">Professor</option>
        </select>
        <div id="divSelect"></div>
    </fieldset>
}

<script>
    $(document).ready(function () {
        $("#UserType").change(function () {
            if (this[this.selectedIndex].value == 2) {
                $("#divSelect").load("/User/GetDepartment", this[this.selectedIndex].value);
            }
            else if (this[this.selectedIndex].value == 3) {
                $("#divSelect").load("/User/RegisterProfessor", this[this.selectedIndex].value);
            }
            else {
                document.getElementById("divSelect").innerHTML = "<button id='create' class='btn'>Create</button>";
                $("#create").click(function () {
                    $.post("/User/CreateAdmin");
                });
            }
        });
    });

    $(document).ready(function () {
        $("#UserType").change();
    });

</script>
